home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000040_icon-group-sender _Thu Feb 8 12:06:34 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 8 Feb 1996 12:21:59 MST
  2. From: Nick Williams <nmw@styx.ios.com>
  3. Message-Id: <199602081706.MAA01427@styx.ios.com>
  4. Subject: Copying procedure blocks
  5. To: icon-group@cs.arizona.edu
  6. Date: Thu, 8 Feb 1996 12:06:34 -0500 (EST)
  7. X-Mailer: ELM [version 2.4 PL23]
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset=US-ASCII
  10. Content-Transfer-Encoding: 7bit
  11. Content-Length: 2912      
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: O
  14.  
  15.  
  16. Hi, several days ago I posted a note about adding closures to Icon as a
  17. feature. Since then I have realized that it would indeed be much easier
  18. to make it so that invoking copy() with a procedure as an argument would
  19. return a new procedure block with new copies of any static variables.
  20.  
  21. It has taken me some time to figure out how to do it, but in the end it
  22. is relatively simple. I've changed a few lines of code and what I have
  23. works, except for a few small bugs that I hope someone can help me with.
  24.  
  25. The main bug is that garbage collection causes core dumps if it also
  26. causes procedure blocks to move around; the other main bug is that I
  27. have not at all delved into how the compiler works, so this feature is
  28. only available with the interpreter.
  29.  
  30. Here's all I did:
  31.  
  32. 1) changed src/icont/lcode.c to output &null descriptors at the end of
  33.    b_proc structures after the descriptors of local/static/argument
  34.    names (and adjusting the blksize field accordingly).
  35.  
  36. 2) changed the implementation of the Op_Static and Op_Astatic Icon
  37.    virtual machine instructions; instead of using the argument to index
  38.    a global table, Op_Static now uses the argument to index the set of
  39.    descriptors at the end of the b_proc structure of the current
  40.    procedure.
  41.  
  42. 3) changed the copy() function to actually make a new copy of its
  43.    argument if it is a procedure.
  44.  
  45. I have yet to go change getvar() and get_name() so that they work with
  46. this scheme, but that too is a fairly simple task. I also intend to
  47. change the implementation of Op_Init and of the refresh operation so
  48. that new copies of procedures can be "refreshed."
  49.  
  50. I have assumed a few things: a) that the garbage collector will continue
  51. to function correctly, since it will sweep the new descriptors at the
  52. end of b_proc sturctures because it uses the blksize field to know when
  53. to stop; and b) that "argp[0]" points to the b_proc structure of the
  54. procedure in whose scope Op_Static and Op_Astatic are being called; and
  55. c) that "argp[0]" is updated if the structure it points to is moved as a
  56. result of a garbage collection event.
  57.  
  58. The changes I have made, btw, fit in one printed page and what remains
  59. to be done to make this scheme work should be just as simple. I just
  60. can't get past why I get these core dumps when procedure blocks are
  61. relocated during garbage collection. If anyone is interested I will post
  62. a set of diffs showing the changes I have made.
  63.  
  64. I plan to use this feature to, among other things, implement a dynamic
  65. RPC mechanism.
  66.  
  67. Nick
  68.  
  69. PS: as this hack stands it involves changes these source files:
  70.  
  71.     src/icont/lcode.c:lemitproc()
  72.     src/runtime/interp.r:interp() [Op_Static and Op_Astatic]
  73.     src/runtime/fmisc.r:copy()
  74.  
  75.     I will also change:
  76.  
  77.     src/runtime/rmisc.r:get_var()
  78.     src/runtime/rdebug.r:getname()
  79.     src/runtime/interp.r:interp() [Op_Init]
  80.     src/h/rstructs.r:struct b_proc [to add a field to help with Op_Init]
  81.